prost = []
for i in range(2, 10000):
    f = 1
    for j in range(2, i//2):
        if i%j == 0:
            f = 0
            break
    if f:
        prost.append(i)
        
itog = 0
ch = input()
if 999 > int(ch) < 10000:
    for i0 in '', ch[0]:
        for i1 in '', ch [1]:
            for i2 in '', ch [2]:
                for i3 in '', ch [3]:
                    if i0+i1+i2+i3:
                        k = int(i0+i1+i2+i3)
                        if k in prost:
                            itog = max(itog, k)
    print(itog)

else:
    print(0)
                
